<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../../includes/config.jsp" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/javascript">
function inicializarFiltro($filtro,$inputKey,$limpar) {
	$($limpar).bind("click",function(event) {
		$inputKey.val("");
		$($filtro).submit();
	  });

	$inputKey.bind("click",function(event) {
		$(this).clearDefault();
	  });
	
	$inputKey.bind("blur",function(event) {
		$(this).loadDefault();
	  });	
	
	$($filtro).bind("submit",function(event) {
		$inputKey.clearDefault();
	  });
}
</script>
<script type="text/javascript">
	function xhrStatus(response, status, xhr) {
		if (status == "error") 
			alert("Erro no XHR: " + xhr.status + " " + xhr.statusText);
	};

	$(document).ready(function () {
		$("a.btn").button();
	
		var $ui = $("#ui-tabs-2");
		var urlAjax = "admmin/acompanhamentos/defesas";

		$(".bt-page").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		});
		
		$("#bt-newers").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");		 
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		}).button({icons: {primary: 'ui-icon ui-icon-triangle-1-w'},text: false});
		
		$("#bt-olders").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		}).button({icons: {primary: 'ui-icon ui-icon-triangle-1-e'},text: false});
		
		$filtro = $("#ui-tabs-1 #filtro");
		$inputKey = $("#ui-tabs-1 #f-keyword");
		$limpar = $("#ui-tabs-1 #f-limpar");
		
		inicializarFiltro($filtro,$inputKey,$limpar);
		$filtro.bind("submit",function(event,form) {
		 event.preventDefault();
		 $filtro.ajaxSubmit({
			url: urlAjax,
			type: 'post',
			success: function(data) {
		  		$ui.html(data);
			}					
		 });
	});		  		
});
</script>
	<script type="text/javascript">
		var proposta_id = 0;
		var defesa_id = 0;
		var aprovar_id = 0;
		var homologar_id = 0;
		var nome_aluno = "";

		function aprovacao_proposta(aprovado_proposta) {
			window.location = "admin/propostas/"+aprovar_id+"/aprovar-"+aprovado_proposta;
		}

		function aprovacao_defesa(aprovado_defesa) {
			window.location = "admin/defesas/"+aprovar_id+"/aprovar-"+aprovado_defesa;
		}

		function homologar(homologado) {
			window.location = "admin/propostas/"+homologar_id+"/homologar-"+homologado;
		}
	
		$(function() {
		
			$(".btn-aprovar-defesa").click(function (event) {
				var dialog = $('#dialog-aprovar-defesa');
				aprovar_id = $(this).attr("title");
				nome_aluno = $(this).attr("alt");
				var title = "Aprovar Defesa de Dissertação de " + nome_aluno;

				event.preventDefault();				
				dialog.dialog("option" , "title" , title);
				dialog.dialog('open');
			});


			$(".btn-detalhes-defesa").click(function (event) {
				var loader = $('#loader_defesa');
				var dialog = $('#dialog-detalhes-defesa');
				var content	= $('#dialog-detalhes-defesa #content_defesa');
				var nome = $(this).attr("alt");
				var title = "Detalhes da Defesa de " + nome;

				loader.show();
				event.preventDefault();
				dialog.dialog("option" , "title" , title);
				dialog.dialog('open');
				content.load($(this).attr("href"), function() {
					$('#loader_defesa').hide();					
					defesa_id = $("#defesa_id").val();
				});
				loader.hide();
			});

			$(".btn-homologar").click(function (event) {
				var dialog = $('#dialog-homologar');
				homologar_id = $(this).attr("title");
				var title = "Homologar Proposta de Dissertação de " + $(this).attr("alt");

				event.preventDefault();				
				dialog.dialog("option" , "title" , title);
				dialog.dialog('open');
			});
		});
	</script>
<c:forEach items="${errors}" var="error">
					<li>${error.category}: ${error.message}</li>
				</c:forEach>
				
				<c:choose>
					<c:when test="${empty defesas}">
						<p>Nenhuma defesa</p>
					</c:when>
					<c:otherwise>
					
			        	<table width="100%" bordercolor="#000000" border="0" cellspacing="3" cellpadding="2">
			              <tr>
			                <th>Nº Processo</th>
			                <th>Data defesa</th>
			                <th>Nome do Orientador</th>
			                <th>Nome do Aluno</th>
			                <th>Status</th>
			                <th>Opções</th>
			              </tr>
			              <c:forEach items="${defesas}" var="defesa" varStatus="c">
			              <tr>
			                <td align="center" bgcolor="#A7D7ED"><fmt:formatNumber value="${defesa.id}" minIntegerDigits="4" groupingUsed=""/></td>
			                <td align="center" bgcolor="#A7D7ED"><fmt:formatDate value="${defesa.data_defesa}" pattern="dd/MM/yyyy"/></td>
			                <td align="center" bgcolor="#A7D7ED">${defesa.orientador.nome}</td>
			                <td align="center" bgcolor="#A7D7ED">${defesa.aluno.nome}</td>
			                <td align="center" bgcolor="#A7D7ED">${defesa.status}</td>
			                <td align="center" bgcolor="#A7D7ED">
			                	<a href="admin/defesas/${defesa.id}" class="btn btn-detalhes-defesa" alt="${defesa.aluno.nome}" id="${defesa.id}" >Detalhes</a>
			                	<c:if test="${defesa.status eq 'HOMOLOGADA'}">
			                		<a href="admin/defesas/${defesa.id}/aprovar" class="btn btn-aprovar-defesa" title="${defesa.id}" alt="${defesa.aluno.nome}">Aprovar</a>
								</c:if>                	
			                </td>
			              </tr>
			              </c:forEach>
			            </table>
					</c:otherwise>
				</c:choose>

<%@include file="../includes/paginacao.jsp" %>